#include "timer.h"
#include "main.h"

static void sigroutine(int signo)
{
}

//使调用线程屏蔽定时器的信号
void mask_sig_alarm()
{
    sigset_t signal_set;
    sigemptyset(&signal_set);
    sigaddset(&signal_set, SIGALRM);
    sigprocmask(SIG_BLOCK, &signal_set, NULL);
}

void start_timer(int sample_period)
{
    //设置定时器与SIGALRM的信号处理函数
    signal(SIGALRM, sigroutine);
    struct itimerval value;
    value.it_value.tv_sec = 0;
    value.it_value.tv_usec = sample_period;
    value.it_interval.tv_sec = 0;
    value.it_interval.tv_usec = sample_period;
    setitimer(ITIMER_REAL, &value, NULL);
}

void stop_timer()
{
    //设置定时器与SIGALRM的信号处理函数
    struct itimerval value;
    value.it_value.tv_sec = 0;
    value.it_value.tv_usec = 0;
    value.it_interval.tv_sec = 0;
    value.it_interval.tv_usec = 0;
    setitimer(ITIMER_REAL, &value, NULL);
}